import React, { Component } from 'react';
import { NavBar, Toast } from 'antd-mobile'
import '../styles/Password.scss'
import service from '../api';
class Pass extends Component {
    constructor(props){
        super(props)
        this.state={
            oldpassword:'',
            newpassword:'',
            userid:''
        }
    }
    async setpass(){
          var res = await service.user.user_updatePassword({oldpassword:this.state.oldpassword,newpassword:this.state.newpassword,userid:localStorage.getItem('userid')})
          if(res.data.code == 200){
            Toast.show(res.data.message)
            this.props.history.push('/login')
          }else if(res.data.code == 10030){
            Toast.show(res.data.message)
          }
    }
onchange(e){
    this.setState({
        [e.target.name]:e.target.type == 'checkbox' ? e.atrget.checked : e.target.value
    })
}
    back(){
        this.props.history.go(-1)
    }
    render() {
        return (
            <div className='password'>
                <div className="top">
                    <NavBar onBack={() => { this.back() }}>修改密码</NavBar>
                </div>
                <div className="name">
                    <input type="text" name='oldpassword' placeholder='请输入旧密码' value={this.state.oldpassword} onChange={(e)=>{this.onchange(e)}} />
                </div>
                <div className="name">
                    <input type="text" name='newpassword' placeholder='请输入新密码' value={this.state.newpassword} onChange={(e)=>{this.onchange(e)}} />
                </div>
                <div className="send">
                    <button onClick={()=>{this.setpass()}}>确认</button>
                </div>
            </div>
        );
    }
}

export default Pass;